import fs from 'fs-extra'
import path from 'path'

export const preOrderDirectoryTraverse = (
  dir: string,
  dirCallback: (fullPath: string) => void,
  fileCallback: (fullPath: string) => void,
) => {
  for (const filename of fs.readdirSync(dir)) {
    // 忽略.git
    if (filename === '.git') {
      continue
    }
    const fullPath = path.resolve(dir, filename)
    if (fs.lstatSync(fullPath).isDirectory()) {
      dirCallback(fullPath)
      if (fs.existsSync(fullPath)) {
        preOrderDirectoryTraverse(fullPath, dirCallback, fileCallback)
      }
      continue
    }
    fileCallback(fullPath)
  }
}
